var shopEnter = new Vue({
    el: '#shopEnterExamine',
    //初始化数据类型
    data: {
        //页面数据
        shopData: {
            //公司名称
            company_name: '',
            //公司联系电话
            tel: '',
            //公司联系邮箱
            mail: '',
            //营业执照
            affiliated_regional: '',
            //组织机构代码
            institution_code: '',
            //法人代表身份证
            id_card_no: '',
            //经营模式
            business_model: ''
        },
        //商家对应的商品信息
        Commodity: [],
        //商家单个信息
        MerchantUnit: {},
        //商家列表信息
        shopDataList: [],
        //更新是否成功
        status: '',
        //搜索框的字段值
        searchion:'',
        //商家当前页
        currentPage:'1',
        //商家显示总条数
        pagesize:'15',
        //商品显示总条数
        pagesizes:'8',
        //商品当前页
        currentPages:'1'

    },
    methods: {
        //显示总条数
        handleSizeChange:function(size,type){
            var _this = this;
            if(type==0){
                _this.pagesize=size;
            }else{
                _this.pagesizes=size;
            }

        },
        //显示当前页
        handleCurrentChange:function(currentPage,type){
            var _this = this;
            if(type==0){
                _this.currentPage = currentPage;
            }else{
                _this.currentPages = currentPage;
            }
        },
        search: function () {
            var _this = this;
            debugger
            $.post("/home/merchant/selectNoCutCommodity", {"id": _this.MerchantUnit.id,"type":_this.searchion}, function (data) {
                   _this.Commodity =  data.data.searchity
            });

        },
        toPass: function (entity, flag) {
            var _this = this;
            debugger
            $.post("/home/merchant/updateNoCut", {"data": JSON.stringify(entity)}, function (data) {
                //初始化商家
                entity.type=1
                if(data.code==200){
                    _this.$message({
                        message: '审核成功！',
                        type: 'success'
                    });
                _this.status = data.data.status;
                if (_this.status) {
                    $("#wrap-left").load("http://" + window.location.host + "/home/shopEnterExamine.html", function () {

                    });
                }
            }else{
                    _this.$message({
                        message: data.data.message,
                        type: 'error'
                    });
                    return;
                }
            });
        },
        //查看商家详情
        toDetailPass: function (shopData) {
            var _this = this;
            $.post("/home/merchant/selectNoCutCommodity", {"id": shopData.id,"type":"0"}, function (data) {
                _this.Commodity = data.data.commodityList;
                /*if(_this.Commodity.length<=10){
                    $("#shopping").attr("class","disabled")
                }else{
                    $("#shopping").attr("class","pre-scrollable")
                }*/

            });
            _this.MerchantUnit = shopData;

        },
        //商品上下架
        handleClick: function (row) {
            var _this = this;
            $.post("/home/commodity/CommodityInstall", {commodity: JSON.stringify(row)}, function (data) {
                if (data.code == 200) {
                    if (row.install == 2) {
                        if (data.data.install == 1) {
                            _this.$message({
                                message: '恭喜你，该商品已上架！',
                                type: 'success'
                            });
                        } else {
                            _this.$message({
                                message: '警告哦，该商品未上架！',
                                type: 'warning'
                            });
                        }

                    } else {
                        if (data.data.install == 1) {
                            _this.$message({
                                message: '恭喜你，商品已下架！',
                                type: 'success'
                            });
                        } else {
                            _this.$message({
                                message: '警告哦，商品未下架！',
                                type: 'warning'
                            });
                        }
                    }
                } else {
                    _this.$message({
                        message: '操作失败！',
                        type: 'error'
                    });
                }
            });


        },
        queryCommodity: function (shopData) {
            var _this = this;
            //先查好商品列表再送过去，避免空数据
            $.post("/home/merchant/selectCommodityByMerchant", {"id": shopData.id}, function (data) {
                _this.Commodity = data.data.commodityList
            });
            $("#wrap-left").load("http://" + window.location.host + "/home/CommodityListByMerchant.html", function () {

            });
        },
        tableRowClassName:function(row, rowIndex) {
            var _this = this;
            if (rowIndex === 0) {
                return 'warning-row';
            }else if(rowIndex === 1) {
                return 'success-row';
            }else if (rowIndex==2) {
                return 'warning-row';
            }else if (rowIndex%2!=0) {
                return 'success-row';
            }else{
                return 'warning-row';
            }
            return '';
        },
    },
    //页面加载完成后执行此方法
    created: function () {
        var _this = this;
        $.post("/home/merchant/selectNoCutByCreateUser",
            '',
            function (data) {
                //初始化商家
                if (data.code == 200) {
                    _this.shopDataList = data.data.shopDataList;
                } else {
                    _this.$message({
                        message: '初始化待审核商家及其商品失败！',
                        type: 'error'
                    });
                }
            });
    },
});
//勿删
$(function(){
    $("#seer").hover(
        function(){
            $("#ert").fadeIn(200,function(){
                $("#ert"). css("display","block");
            });
        },
        function(){
            $("#ert").fadeOut(200,function(){
                $("#ert"). css("display","none");
            });
        }
    );
});